<?php
/**
 * Created by PhpStorm.
 * User: admin
 * Date: 2019/12/6
 * Time: 10:16
 */

namespace app\adminapiv3\service;


class Menu extends Base
{
    /**
     * @name 菜单 只验证模块授权与否,不根据用户等级做相对应的菜单展示
     * @author wx
     * @date 2019/12/6 10:16
     */
    function menu()
    {
        $server = new \app\common\model\Menu();

        $allMenu = $server->allMenu;
        $MenuArr = json_decode($allMenu, true);

        $authServer = new \app\common\service\ServerAuth();

        foreach ($MenuArr as $k => $v){

            if($v['text'] == '模块管理'){

                foreach ($v['children'] as $ck => $cv){

                    $authInfo = $authServer->findData(['module_name' => $cv['text']], 'id, module_name, product_key');

                    if(empty($authInfo)){
                        $v['children'][$ck]['redirect'] = '/unauthorized';
                    }

                }

                $MenuArr[$k] = $v;
            }
        }

        return $MenuArr;
    }

}